package lesson5;

import java.util.Scanner;

//6、计算任意一个整数(int)的二进制。
public class Demo6 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入整数...");
        int num = scanner.nextInt();
        int[] bitArr = new int[32];
        if(num < 0){
            bitArr[0] = 1;
            num = num*(-1);
        }else{
            bitArr[0] = 0;
        }

        int index = bitArr.length-1;
        while(num != 0){
            bitArr[index] = num%2;
            index--;
            num = num/2;
        }

        for(int i = 0; i < bitArr.length; i++){
            System.out.print(bitArr[i]);
            if(i!=0 && (i+1)%8 == 0){
                System.out.print(" ");
            }
        }
    }
}
